﻿// Decompiled with JetBrains decompiler
// Type: CreateMfgByCoordinates.CUiCreCreateMfgForm
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using System;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Windows.Forms;
using Tecnomatix.Engineering;
using Tecnomatix.Engineering.Ui;


namespace CreateMfgByCoordinates;

public class CUiCreCreateMfgForm : TxForm
{
  private Container components;
  private TextBox m_mfgName;
  private Label m_pointLabel;
  private Button m_buttonOK;
  private Button m_buttonCancel;
  private Label m_partLabel;
  private TxObjEditBoxCtrl m_part;
  private Label m_mfgNameLabel;
  private TxFrameEditBoxCtrl m_frame;
  private CApCreDialogManager m_manager;

  public CUiCreCreateMfgForm() => this.InitializeComponent();

  private void InitializeComponent()
  {
    ComponentResourceManager componentResourceManager = new ComponentResourceManager(typeof (CUiCreCreateMfgForm));
    this.m_mfgName = new TextBox();
    this.m_mfgNameLabel = new Label();
    this.m_pointLabel = new Label();
    this.m_partLabel = new Label();
    this.m_buttonCancel = new Button();
    this.m_buttonOK = new Button();
    this.m_part = new TxObjEditBoxCtrl();
    this.m_frame = new TxFrameEditBoxCtrl();
    ((Control) this).SuspendLayout();
    componentResourceManager.ApplyResources((object) this.m_mfgName, "m_mfgName");
    this.m_mfgName.Name = "m_mfgName";
    componentResourceManager.ApplyResources((object) this.m_mfgNameLabel, "m_mfgNameLabel");
    this.m_mfgNameLabel.Name = "m_mfgNameLabel";
    componentResourceManager.ApplyResources((object) this.m_pointLabel, "m_pointLabel");
    this.m_pointLabel.Name = "m_pointLabel";
    componentResourceManager.ApplyResources((object) this.m_partLabel, "m_partLabel");
    this.m_partLabel.Name = "m_partLabel";
    this.m_buttonCancel.DialogResult = DialogResult.Cancel;
    componentResourceManager.ApplyResources((object) this.m_buttonCancel, "m_buttonCancel");
    this.m_buttonCancel.Name = "m_buttonCancel";
    this.m_buttonCancel.Click += new EventHandler(this.m_buttonCancel_Click);
    componentResourceManager.ApplyResources((object) this.m_buttonOK, "m_buttonOK");
    this.m_buttonOK.Name = "m_buttonOK";
    this.m_buttonOK.Click += new EventHandler(this.m_buttonOK_Click);
    this.m_part.KeepFaceEmphasizedWhenControlIsNotFocused = true;
    this.m_part.ListenToPick = true;
    componentResourceManager.ApplyResources((object) this.m_part, "m_part");
    ((Control) this.m_part).Name = "m_part";
    this.m_part.Object = (ITxObject) null;
    this.m_part.PickAndClear = false;
    this.m_part.PickLevel = (TxPickLevel) 1;
    this.m_part.PickOnly = false;
    this.m_part.ReadOnly = false;
    this.m_part.ValidatorType = (TxValidatorType) 1;
    this.m_frame.EnableRelativeToWorkingFrameCoordinates = true;
    this.m_frame.ListenToPick = true;
    componentResourceManager.ApplyResources((object) this.m_frame, "m_frame");
    ((Control) this.m_frame).Name = "m_frame";
    this.m_frame.PickLevel = (TxPickLevel) 6;
    this.m_frame.ValidatorType = (TxValidatorType) 1;
    this.m_frame.VisualizePickedFrameInGraphicViewer = false;
    this.m_frame.ValidFrameSet += new TxFrameEditBoxCtrl_ValidFrameSetEventHandler(this.m_frame_ValidFrameSet);
    this.m_frame.Picked += new TxFrameEditBoxCtrl_PickedEventHandler(this.m_frame_Picked);
    ((Form) this).AcceptButton = (IButtonControl) this.m_buttonOK;
    componentResourceManager.ApplyResources((object) this, "$this");
    ((Form) this).CancelButton = (IButtonControl) this.m_buttonCancel;
    ((Control) this).Controls.Add((Control) this.m_frame);
    ((Control) this).Controls.Add((Control) this.m_mfgName);
    ((Control) this).Controls.Add((Control) this.m_part);
    ((Control) this).Controls.Add((Control) this.m_buttonOK);
    ((Control) this).Controls.Add((Control) this.m_buttonCancel);
    ((Control) this).Controls.Add((Control) this.m_partLabel);
    ((Control) this).Controls.Add((Control) this.m_pointLabel);
    ((Control) this).Controls.Add((Control) this.m_mfgNameLabel);
    ((Form) this).FormBorderStyle = FormBorderStyle.FixedDialog;
    ((Form) this).MaximizeBox = false;
    ((Form) this).MinimizeBox = false;
    ((Control) this).Name = nameof (CUiCreCreateMfgForm);
    ((Form) this).Closed += new EventHandler(this.CUiCreCreateMfgForm_Closed);
    ((Form) this).Load += new EventHandler(this.CUiCreCreateMfgForm_Load);
    ((Control) this).ResumeLayout(false);
    ((Control) this).PerformLayout();
  }

  protected virtual void Dispose(bool disposing)
  {
    if (disposing && this.components != null)
      this.components.Dispose();
    base.Dispose(disposing);
  }

  public void Show(TxObjectList selectedObjects)
  {
    this.m_manager = new CApCreDialogManager();
    if (((Collection<ITxObject>) selectedObjects).Count == 1 && this.m_manager.IsPart(((Collection<ITxObject>) selectedObjects)[0]))
      this.m_part.Object = ((Collection<ITxObject>) selectedObjects)[0];
    ((Control) this).Show();
  }

  private void m_buttonCancel_Click(object sender, EventArgs e)
  {
    this.m_manager.Cancel();
    ((Form) this).Close();
  }

  private void m_buttonOK_Click(object sender, EventArgs e)
  {
    TxTransformation txTransformation;
    try
    {
      txTransformation = this.m_frame.GetLocation();
    }
    catch (NullReferenceException ex)
    {
      txTransformation = TxApplication.ActiveDocument.WorkingFrame;
    }
    this.m_manager.Accept(this.m_mfgName.Text, this.m_frame.GetLocation(), (ITxObject) (this.m_part.Object as ITxProcessModelObject));
    ((Form) this).Close();
  }

  private void m_frame_Picked(object sender, TxFrameEditBoxCtrl_PickedEventArgs args)
  {
    if (!this.m_manager.IsPart(args.Object))
      return;
    this.m_part.Object = (ITxObject) (args.Object as ITxProcessModelObject);
  }

  private void m_frame_ValidFrameSet(object sender, TxFrameEditBoxCtrl_ValidFrameSetEventArgs args)
  {
    this.m_manager.SetTemporaryFrame(this.m_frame.GetLocation());
  }

  private void CUiCreCreateMfgForm_Load(object sender, EventArgs e)
  {
    this.m_mfgName.Text = TxApplication.ActiveDocument.PhysicalRoot.GetUniqueDisplayName("wp");
    this.m_part.SetValidator((ITxValidator) this.m_manager.PartValidator);
  }

  private void CUiCreCreateMfgForm_Closed(object sender, EventArgs e)
  {
    this.m_frame.LoseFocus();
    this.m_part.LoseFocus();
  }
}
